package com.wdb.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wdb.modules.system.domain.User;
import com.wdb.modules.system.domain.vo.UserQueryCriteriaDTO;
import com.wdb.modules.system.mapper.UserMapper;
import com.wdb.modules.system.service.UserService;
import com.wdb.utils.PageResult;
import com.wdb.utils.PageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

/**
 * @author: wendaobai@qq.com
 * @date: 2024/1/16 0016 16:16
 */
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "user")
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
  private final UserMapper userMapper;

  @Override
  public User getLoginData(String userName) {

    return userMapper.findByUsername(userName);
  }

  @Override
  public PageResult<User> getAll(UserQueryCriteriaDTO userQueryCriteria, Page page) {
    Page<User> users = userMapper.getAll(userQueryCriteria, page);
    PageResult<User> userPageResult = PageUtil.toPage(users);

    return userPageResult;
  }
}
